package com.liveinstars.im.common.dto;

import com.liveinstars.api.im.vo.ChatGroupMsgReportRecordVO;
import com.liveinstars.api.im.vo.ChatGroupMsgReportVO;
import com.liveinstars.im.common.enums.ReportStatusEnum;
import com.liveinstars.im.common.enums.ReportTypeEnum;
import com.liveinstars.im.constant.ServerConstant;
import com.liveinstars.im.domain.dao.model.Report;
import com.liveinstars.im.entity.ChatMessage;
import com.onepiece.shipelves.common.constant.Constant;
import lombok.Data;
import lombok.ToString;

import java.time.ZoneOffset;

/**
 * @author: zhouze
 * @date: 2020/3/5
 */
@Data
@ToString
public class ReportDTO {

    private Report report;

    private String chatGroupName;

    private String reportedUserName;

    private String reportUserName;

    public ReportDTO(Report report) {
        this.report = report;
    }

    public ReportDTO(ChatMessage chatMessage, ChatGroupMsgReportVO vo) {
        Report report = new Report();
        report.setFromId(vo.getChatGroupId());
        report.setType(vo.getType());
        report.setReportContent(chatMessage.getContent());
        report.setReportUserId(vo.getReportUserId());
        report.setReportedUserId(chatMessage.getFromId());
        report.setSourceId(chatMessage.getId());
        report.setSourceType(ServerConstant.UCG_MSG_REPORT);
        report.setState(Constant.STATE_VALID);
        report.setStatus(ReportStatusEnum.UN_DO.getValue());
        this.report = report;
    }

    public ChatGroupMsgReportRecordVO transTo() {
        ChatGroupMsgReportRecordVO vo = new ChatGroupMsgReportRecordVO();
        vo.setId(report.getId());
        vo.setChatGroupId(report.getFromId());
        vo.setType(report.getType());
        vo.setTypeStr(ReportTypeEnum.valueOf(report.getType()).getText());
        vo.setMsgId(report.getSourceId());
        vo.setReportUserId(report.getReportUserId());
        vo.setReportTime(report.getCstCreated().toEpochSecond(ZoneOffset.of("+8")));
        vo.setStatus(report.getStatus());
        vo.setMsg(report.getReportContent());
        vo.setReportedUserId(report.getReportedUserId());
        vo.setChatGroupName(this.getChatGroupName());
        vo.setReportedUserName(this.getReportedUserName());
        vo.setReportUserName(this.getReportUserName());
        return vo;
    }

}
